<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>车辆违章查询系统</title>
    <style>
        /* 基础样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', Arial, sans-serif;
            background: #f0f2f5;
            padding: 20px;
            min-height: 100vh;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        h1 {
            color: #1a73e8;
            text-align: center;
            margin-bottom: 30px;
            font-size: 24px;
        }

        .search-box {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }

        input {
            flex: 1;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
        }

        button {
            padding: 12px 30px;
            background: #1a73e8;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: background 0.3s;
        }

        button:hover {
            background: #1557b0;
        }

        .result {
            margin-top: 20px;
        }

        .violation-item {
            padding: 15px;
            border: 1px solid #eee;
            border-radius: 6px;
            margin-bottom: 10px;
            background: #f8f9fa;
        }

        .violation-item p {
            margin: 5px 0;
            color: #333;
        }

        .status {
            font-weight: bold;
        }

        .status.unprocessed {
            color: #dc3545;
        }

        .status.processed {
            color: #28a745;
        }

        .no-data {
            text-align: center;
            color: #6c757d;
            padding: 20px;
        }

        /* 移动端适配 */
        @media (max-width: 480px) {
            .container {
                padding: 15px;
            }
            
            .search-box {
                flex-direction: column;
            }
            
            button {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>车辆违章查询系统</h1>
        <div class="search-box">
            <input 
                type="text" 
                id="carPlate" 
                placeholder="请输入完整车牌号（如：沪A12345）"
                maxlength="8"
            >
            <button onclick="searchViolation()">立即查询</button>
        </div>
        <div id="result" class="result"></div>
    </div>

    <script>
        // ================= 配置项 =================
        const DATA_URL = 'https://gitee.com/frankliguofeng/violation-inquiry.git';
        const QUERY_INTERVAL = 3000; // 防刷间隔(毫秒)

        // ================= 核心逻辑 =================
        let lastQueryTime = 0;

        async function searchViolation() {
            const carPlate = document.getElementById('carPlate').value.trim();
            const resultDiv = document.getElementById('result');
            
            // 输入验证
            if (!carPlate) {
                showError('请输入车牌号');
                return;
            }

            // 防刷机制
            if (Date.now() - lastQueryTime < QUERY_INTERVAL) {
                showError('查询过于频繁，请稍后再试');
                return;
            }
            lastQueryTime = Date.now();

            try {
                // 加载数据
                const response = await fetch(DATA_URL);
                const data = await response.json();

                // 过滤结果
                const filteredData = data.filter(item => 
                    item.car_plate.toUpperCase() === carPlate.toUpperCase()
                );

                // 展示结果
                displayResults(filteredData);
            } catch (error) {
                showError('数据加载失败，请检查网络连接');
            }
        }

        // ================= 显示函数 =================
        function displayResults(data) {
            const resultDiv = document.getElementById('result');
            
            if (data.length === 0) {
                resultDiv.innerHTML = `
                    <div class="no-data">
                        <p>未找到该车辆的违章记录</p>
                        <p>🚗 安全驾驶，继续保持！</p>
                    </div>
                `;
                return;
            }

            let html = '';
            data.forEach(item => {
                html += `
                    <div class="violation-item">
                        <p>车牌号码：${maskPlate(item.car_plate)}</p>
                        <p>违章时间：${item.violation_time}</p>
                        <p>违章地点：${item.location}</p>
                        <p>处罚金额：${item.fine}元</p>
                        <p>扣分情况：${item.points}分</p>
                        <p class="status ${item.status === '未处理' ? 'unprocessed' : 'processed'}">
                            处理状态：${item.status}
                        </p>
                    </div>
                `;
            });

            resultDiv.innerHTML = html;
        }

        function showError(message) {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = `
                <div class="violation-item" style="color: #dc3545;">
                    ${message}
                </div>
            `;
        }

        // ================= 工具函数 =================
        function maskPlate(plate) {
            return plate.slice(0, 2) + '****' + plate.slice(-1);
        }
    </script>
</body>
</html>